
	#include "ADCDriver.h"
	
	void VfnADCInitialization(void)
	{
		SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
		SysCtlADCSpeedSet(SYSCTL_ADCSPEED_125KSPS);
		
		SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
		GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_7);
		GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_6);
		
		ADCSequenceDisable(ADC_BASE, 0);
		
		#if  SS0_ENABLE == ON
			//////////////////////////////////////
			//	Sequencer 0 configuration		//
			//////////////////////////////////////
			#if SS0_TRIGGER == TRIGGER_ALWAYS
				ADCSequenceConfigure(ADC0_BASE, 0,ADC_TRIGGER_ALWAYS, 1);
				// Last parameter idicates Prioritization, range 0-3. with 0 being the highest.
			#endif
			#if SS0_TRIGGER == TRIGGER_PROCESSOR
				ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 1);
				// Last parameter idicates Prioritization, range 0-3. with 0 being the highest.
			#endif
			#if SS0_TRIGGER == TRIGGER_TIMER
				ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_TIMER, 1);
				// Last parameter idicates Prioritization, range 0-3. with 0 being the highest.
			#endif
			//////////////////////////////////////////////////////////////
			// 				**	Sequencer configuration	** 				//
			//	*NOTE User MUST modify this section according your CODE //
			//////////////////////////////////////////////////////////////
			ADCSequenceStepConfigure(ADC0_BASE, 0, 0,ADC_CTL_CH0);
			ADCSequenceStepConfigure(ADC0_BASE, 0, 1,ADC_CTL_CH1);
			ADCSequenceStepConfigure(ADC0_BASE, 0, 2,ADC_CTL_CH1);
			ADCSequenceStepConfigure(ADC0_BASE, 0, 3,ADC_CTL_TS);
			ADCSequenceStepConfigure(ADC0_BASE, 0, 4,ADC_CTL_TS |  ADC_CTL_IE  | ADC_CTL_END);
			// ADC hardware oversample by 8	//
			ADCHardwareOversampleConfigure(ADC_BASE, 8);
			// Enable Sequencer 0	//
			ADCSequenceEnable(ADC0_BASE, 0);
			
			#if SS0_TRIGGER == TRIGGER_PROCESSOR
				ADCProcessorTrigger(ADC0_BASE, 0);
			#endif
			//////////////////////////////////////////////////
			//		Sequencer 0 Interruption Enable			//
			//////////////////////////////////////////////////
			ADCIntEnable(ADC_BASE, 0);
			IntEnable(INT_ADC0);
		#endif
		
		#if	 SS1_ENABLE == ON
			//////////////////////////////////////
			//	Sequencer 1 configuration		//
			//////////////////////////////////////
			ADCSequenceDisable(ADC_BASE, 1);
			#if SS1_TRIGGER == TRIGGER_ALWAYS
				ADCSequenceConfigure(ADC0_BASE, 1,ADC_TRIGGER_ALWAYS, 0);
				// Last parameter idicates Prioritization, range 0-3. with 0 being the highest.
			#endif
			#if SS1_TRIGGER == TRIGGER_PROCESSOR
				ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
				// Last parameter idicates Prioritization, range 0-3. with 0 being the highest.
			#endif
			#if SS1_TRIGGER == TRIGGER_TIMER
				ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_TIMER, 0);
				// Last parameter idicates Prioritization, range 0-3. with 0 being the highest.
			#endif
			//////////////////////////////////////////////////////////////
			// 				**	Sequencer configuration	** 				//
			//	*NOTE User MUST modify this section according your CODE //
			//////////////////////////////////////////////////////////////
			//ADCSequenceStepConfigure(ADC0_BASE, 1, 0,ADC_CTL_CH0);
			//ADCSequenceStepConfigure(ADC0_BASE, 1, 1,ADC_CTL_CH1);
			//ADCSequenceStepConfigure(ADC0_BASE, 1, 2,ADC_CTL_CH1);
			ADCSequenceStepConfigure(ADC0_BASE, 1, 0,ADC_CTL_TS |  ADC_CTL_IE | ADC_CTL_END);
			// ADC hardware oversample by 8	//
			//ADCHardwareOversampleConfigure(ADC_BASE, 8);
			// Enable Sequencer 0	//
			ADCSequenceEnable(ADC0_BASE, 1);
			
			#if SS1_TRIGGER == TRIGGER_PROCESSOR
				ADCProcessorTrigger(ADC0_BASE, 1);
			#endif
			//////////////////////////////////////////////////
			//		Sequencer 1 Interruption Enable			//
			//////////////////////////////////////////////////
			ADCIntEnable(ADC0_BASE, 1);
			IntEnable(INT_ADC1);
		#endif
		
		#if  SS2_ENABLE == ON
			//////////////////////////////////////
			//	Sequencer 2 configuration		//
			//////////////////////////////////////
			ADCSequenceConfigure(ADC0_BASE, 2, ADC_TRIGGER_PROCESSOR, 0);
			ADCSequenceStepConfigure(ADC0_BASE, 2, 0, ADC_CTL_IE  | ADC_CTL_CH1 | ADC_CTL_END);
			ADCSequenceEnable(ADC0_BASE, 2);
			ADCProcessorTrigger(ADC0_BASE, 2);
			
			//////////////////////////////////////////////////
			//		Sequencer 2 Interruption Enable			//
			//////////////////////////////////////////////////
			ADCIntEnable(ADC_BASE, 2);
			IntEnable(INT_ADC2);
		#endif
		
		#if  SS3_ENABLE == ON
			//////////////////////////////////////
			//	Sequencer 3 configuration		//
			//////////////////////////////////////
			ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
			ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_IE  | ADC_CTL_CH0 | ADC_CTL_END);
			ADCSequenceEnable(ADC0_BASE, 3);
			ADCProcessorTrigger(ADC0_BASE, 3);
			
			//////////////////////////////////////////////////
			//		Sequencer 3 Interruption Enable			//
			//////////////////////////////////////////////////
			ADCIntEnable(ADC_BASE, 3);
			IntEnable(INT_ADC3);
		#endif
	}
	
	void VfnADCSequencer0Read(unsigned long *datoADC_ptr)
	{
		ADCSequenceDataGet(ADC0_BASE, 0, datoADC_ptr);
	}
	
	void VfnADCSequencer1Read(unsigned long *datoADC_ptr)
	{
		ADCSequenceDataGet(ADC0_BASE, 1, datoADC_ptr);
	}
